home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacsBug / MacsBug 6.1 / dcmds / Contributed dcmds / Put.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-21  |  2.9 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*    put.c
  2.     This is a set of formatting routines for use by dcmds.
  3.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  4.  
  5.     Modification history:
  6.         29Nov88 sad        revised for new dcmd names.
  7.          5Oct88 sad        written from file.c
  8.  */
  9.  
  10. #include <Types.h>
  11. #include <Memory.h>
  12.  
  13. #include "dcmd.h"
  14.  
  15. static Str255 line;
  16. static int linepos = 0;
  17.  
  18.  
  19. void PutLine()
  20. {
  21.     BlockMove(line,line+1,linepos);
  22.     line[0] = linepos;
  23.     dcmdDrawLine(line);
  24.     linepos = 0;
  25. } // PutLine
  26.  
  27.  
  28. void PutChar(char c)
  29. {
  30.     line[linepos++] = c;
  31. } // PutChar
  32.  
  33.  
  34. void PutSpace()
  35. {
  36.     PutChar(' ');
  37. } // PutSpace
  38.  
  39.  
  40. void PutSpacesTo(int pos)
  41. {
  42.     while (linepos < pos) PutSpace();
  43. } // PutSpacesTo
  44.  
  45.  
  46. void PutBytesTruncTo(const char* s, int len, int pos)
  47. {
  48.     if (pos > linepos)
  49.         {
  50.         if (len <= pos - linepos)
  51.             {
  52.             BlockMove(s,line+linepos,len);
  53.             linepos += len;
  54.             while (linepos < pos) PutSpace();
  55.             }
  56.         else
  57.             {
  58.             BlockMove(s,line+linepos,pos-linepos-1);
  59.             linepos = pos - 1;
  60.             PutChar('…');
  61.             }
  62.         line[linepos] = '\0';
  63.         }
  64. } // PutBytesTruncTo
  65.  
  66.  
  67. void PutBytesTo(const char* s, int len, int pos)
  68. {
  69.     BlockMove(s,line+linepos,len);
  70.     linepos += len;
  71.     while (linepos < pos) PutSpace();
  72.     line[linepos] = '\0';
  73. } // PutBytesTo
  74.  
  75.  
  76. void PutCStrTo(const char* s, int pos)
  77. {
  78.     int slen = strlen(s);
  79.     PutBytesTo(s,slen,pos);
  80. } // PutCStrTo
  81.  
  82.  
  83. void PutCStrTruncTo(const char* s, int pos)
  84. {
  85.     int slen = strlen(s);
  86.     PutBytesTruncTo(s,slen,pos);
  87. } // PutCStrTo
  88.  
  89.  
  90. void PutCStr(const char* s)
  91. {
  92.     int slen = strlen(s);
  93.     PutBytesTo(s,slen,0);
  94. } // PutCStr
  95.  
  96.  
  97. void PutPStrTruncTo(const char* s, int pos)
  98. {
  99.     int slen = *(unsigned char *)s;
  100.     PutBytesTruncTo(s+1,slen,pos);
  101. } // PutPStrTo
  102.  
  103.  
  104. void PutPStrTo(const char* s, int pos)
  105. {
  106.     int slen = *(unsigned char *)s;
  107.     PutBytesTo(s+1,slen,pos);
  108. } // PutPStrTo
  109.  
  110.  
  111. void PutPStr(const char* s)
  112. {
  113.     int slen = *(unsigned char *)s;
  114.     PutBytesTo(s+1,slen,0);
  115. } // PutPStr
  116.  
  117.  
  118. void PutUHexZTo(unsigned long i, int ndig, int pos)
  119. {
  120. unsigned long dig = i % 0x10;
  121. unsigned long rest = i / 0x10;
  122.     if (rest != 0) PutUHexZTo(rest,ndig - 1,pos - 1);
  123.     else
  124.         {
  125.         pos -= 1;        // one for this digit
  126.         if (ndig > 0) pos -= ndig - 1;        // the leading zeros
  127.         while (linepos < pos) PutSpace();
  128.         while (--ndig > 0) PutChar('0');
  129.         }
  130.     if (dig < 10) PutChar('0' + dig);
  131.     else PutChar('a' + (dig - 10));
  132. } // PutUHexZTo
  133.  
  134.  
  135. void PutUHexZ(unsigned long i, int nz)
  136. {
  137.     PutUHexZTo(i,nz,0);
  138. } // PutUHexZ
  139.  
  140.  
  141. void PutUHexWord(unsigned long i)
  142. {
  143.     PutUHexZTo((unsigned short)i,4,0);
  144. } // PutUHexZ
  145.  
  146.  
  147. void PutUDecTo(unsigned long i, int pos)
  148. {
  149. unsigned long dig = i % 10;
  150. unsigned long rest = i / 10;
  151.     if (rest != 0) PutUDecTo(rest,pos - 1);
  152.     else
  153.         {
  154.         pos -= 2;    // one for the '#' and one for this digit
  155.         while (linepos < pos) PutSpace();
  156.         PutChar('#');
  157.         }
  158.     PutChar('0' + dig);
  159. } // PutUDecTo
  160.  
  161.  
  162. void PutUDec(unsigned long i)
  163. {
  164.     PutUDecTo(i,0);
  165. } // PutUDec
  166.  
  167.  
  168. void PutOSType(unsigned long typ)
  169. {
  170.     PutChar((typ>>24) & 0xff);
  171.     PutChar((typ>>16) & 0xff);
  172.     PutChar((typ>>8) & 0xff);
  173.     PutChar(typ & 0xff);
  174. } // PutOSType
  175.